package com.czl.module_service.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.data.bean.tengyun.AssetHandleFacilityBean
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemAssetHandleFacilityInuseBinding

class AssetHandleFacilityInuseAdapter :
    BaseQuickAdapter<AssetHandleFacilityBean, BaseDataBindingHolder<ItemAssetHandleFacilityInuseBinding>>(
        R.layout.item_asset_handle_facility_inuse
    ) {

    var facilityIdList: ArrayList<Int> = arrayListOf()

    override fun convert(
        holder: BaseDataBindingHolder<ItemAssetHandleFacilityInuseBinding>,
        item: AssetHandleFacilityBean,
    ) {
        holder.dataBinding?.run {
            item.position = holder.layoutPosition
            item.selectedInList = facilityIdList.contains(item.id)
            data = item
            adapter = this@AssetHandleFacilityInuseAdapter
            executePendingBindings()
        }
    }

    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is AssetHandleFacilityBean) {
            if (!it.selectedInList!!) {
                var item: AssetHandleFacilityBean = it
                item.selected = !item.selected!!
                setData(item.position!!, item)
            }
        }
    })
}
